Golang 入门系列(十一)Go语言实现webapi | 您所在的位置:网站首页 › go语言 web开发 › Golang 入门系列(十一)Go语言实现webapi |
package controller import ( "net/http" "micro-cloud/service" "micro-cloud/utils" "micro-cloud/framework") /** * r.PostFormValue : 可以解析 Post/PUT Content-Type=application/x-www-form-urlencoded 或 Content-Type=multipart/form-data */ type UserConterller struct { } var userService = new(service.UserService) func (p *UserConterller) Router(router *framework.RouterHandler) { router.Router("/register", p.register) router.Router("/login", p.login) router.Router("/findAll", p.findAll)} //POST Content-Type=application/x-www-form-urlencodedfunc (p *UserConterller) register(w http.ResponseWriter, r *http.Request) { username := r.PostFormValue("username") password := r.PostFormValue("password") if utils.Empty(username) || utils.Empty(password) { microcloud.ResultFail(w, "username or password can not be empty") return } id := userService.Insert(username, password) if id |
CopyRight 2018-2019 实验室设备网 版权所有 |